package dev.ece.suit.hexmap;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import dev.ece.core.texture.Texture;
import dev.ece.util.lib.Vector3f;

@Deprecated
public class HexMapChunk {

	private List<HexMapCell> cells = new ArrayList<HexMapCell>();
	
	private List<HexMapCrevice> crevices = new ArrayList<HexMapCrevice>();
	
	private List<HexMapTriangle> triangles = new ArrayList<HexMapTriangle>();
	
	private List<HexMapWaterCell> waters = new ArrayList<HexMapWaterCell>();
	
	private boolean visible;

	
	public void render(HexMapCellShader hexMapCellShader, Texture[] textures) {
		if(this.isVisible()) {
			Iterator<HexMapCell> it = cells.iterator();
			while(it.hasNext()) {
				it.next().render(hexMapCellShader, textures);
			}
		}
	}
	
	public void render(HexMapCreviceShader hexMapCreviceShader, Texture[] textures) {
		if(this.isVisible()) {
			Iterator<HexMapCrevice> it = crevices.iterator();
			while(it.hasNext()) {
				it.next().render(hexMapCreviceShader, textures);
			}
		}
	}
	
	public void render(HexMapTriangleShader hexMapTriangleShader, Texture[] textures) {
		if(this.isVisible()) {
			Iterator<HexMapTriangle> it = triangles.iterator();
			while(it.hasNext()) {
				it.next().render(hexMapTriangleShader, textures);
			}
		}
	}
	
	public void render(HexMapWaterShader hexMapWaterShader) {
		if(this.isVisible()) {
			Iterator<HexMapWaterCell> it = waters.iterator();
			while(it.hasNext()) {
				it.next().render(hexMapWaterShader);
			}
		}
	}
	
	public void renderCellDepthMap() {
		if(this.isVisible()) {
			Iterator<HexMapCell> it = cells.iterator();
			while(it.hasNext()) {
				it.next().renderDepthMap();
			}
		}
	}
	
	public void renderCreviceDepthMap() {
		if(this.isVisible()) {
			Iterator<HexMapCrevice> c_it = this.crevices.iterator();
			while(c_it.hasNext()) {
				c_it.next().renderDepthMap();
			}
		}
	}
	
	public void renderTriangleDepthMap() {
		if(this.isVisible()) {
			Iterator<HexMapTriangle> t_it = this.triangles.iterator();
			while(t_it.hasNext()) {
				t_it.next().renderDepthMap();
			}
		}
	}
	
	public void setAutoVisible(float x, float z, float distance) {
		this.setVisible(false);
		Iterator<HexMapCell> it = cells.iterator();
		HexMapCell cell = null;
		Vector3f center = null;
		while(it.hasNext()) {
			cell = it.next();
			center = cell.getVertice().get(0);
			if(Math.abs(x - center.getX()) < distance && Math.abs(z - center.getZ()) < distance) {
				this.setVisible(true);
				return;
			}
		}
	}
	
	public boolean isVisible() {
		return visible;
	}

	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	public List<HexMapCell> getCells() {
		return cells;
	}

	public List<HexMapCrevice> getCrevices() {
		return crevices;
	}

	public List<HexMapTriangle> getTriangles() {
		return triangles;
	}

	public List<HexMapWaterCell> getWaters() {
		return waters;
	}
	
}
